package com.example.mvplibrary.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

/**
 * 项目名：p7_2_zong
 * 包名： com.example.mvplibrary.adapter
 * 文件名：MultipleAdapter
 * 创建者：朱勇闯
 * 创建时间：2021/3/18  15:47
 * 描述：TODO
 */
public abstract class BaseAdapter<DATA> extends RecyclerView.Adapter<BaseViewHolder> {
    protected List<DATA> datas;
    protected Context context;
    protected LayoutInflater layoutInflater;
    protected int layoutId;
    protected itemOnClick itemOnClick;


    public BaseAdapter(List<DATA> datas, Context context, int layoutId) {
        this.datas = datas;
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.layoutId = layoutId;

    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(layoutInflater.inflate(layoutId, parent, false));
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        bindData(holder, datas.get(position), position);
    }

    protected abstract void bindData(BaseViewHolder holder, DATA data, int position);


    @Override
    public int getItemCount() {
        return datas.size();
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    public interface itemOnClick {
        void onClick(int pos);
    }
}
